package com.yanqu.road.server.timer.cross3;

import com.yanqu.road.logic.xlogic.rank.channel.XChannelRankMap;
import com.yanqu.road.logic.xlogic.rank.season.XSeasonUserRankMap;
import com.yanqu.road.logic.xlogic.rank.user.XUserRankMap;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.cross3.activity.XRankProto;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.cross3.GameXRankMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.utils.executor.GeneralTask;

import java.util.List;

public class GameXRankTask extends GeneralTask {

    @Override
    public void doRun() {

        // 上传 个人榜
        XUserRankMap userRankMap = GameXRankMgr.getUserRankMap();
        List<XRankProto.XUserRankListMsg.Builder> cacheList = userRankMap.getSyncCacheAndClear(false);
        for (XRankProto.XUserRankListMsg.Builder builder : cacheList) {
            YanQuMessage pbMessage = YanQuMessageUtils.buildMessage(Cross3Protocol.C3_XRANK_UPLOAD_USER_RANK_FROM_GAME, builder);
            GamePlayerMgr.sendPacket(0, pbMessage);
        }

        // 上传 区域榜 个人贡献
        XChannelRankMap channelRankMap = GameXRankMgr.getChannelRankMap();
        List<XRankProto.XChannelRankPartListMsg.Builder> partList = channelRankMap.getSyncPartCacheAndClear();
        for (XRankProto.XChannelRankPartListMsg.Builder builder : partList) {
            YanQuMessage pbMessage = YanQuMessageUtils.buildMessage(Cross3Protocol.C3_XRANK_UPLOAD_CHANNEL_RANK_PART_FROM_GAME, builder);
            GamePlayerMgr.sendPacket(0, pbMessage);
        }

        // 上传 赛季个人榜
        XSeasonUserRankMap seasonUserRankMap = GameXRankMgr.getSeasonUserRankMap();
        List<XRankProto.XSeasonUserRankListMsg.Builder> cacheSeasonList = seasonUserRankMap.getSyncCacheAndClear(false);
        for (XRankProto.XSeasonUserRankListMsg.Builder builder : cacheSeasonList) {
            // 直接全部发送
            YanQuMessage pbMessage = YanQuMessageUtils.buildMessage(Cross3Protocol.C3_XRANK_UPLOAD_SEASON_USER_RANK_FROM_GAME, builder);
            GamePlayerMgr.sendPacket(0, pbMessage);
        }
    }
}
